<?php

/**
 * This file is part of Switcher.
 * 
 * Switcher is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Switcher is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Switcher. If not, see <http://www.gnu.org/licenses/>.
 * 
 * @license http://www.opensource.org/licenses/gpl-3.0.html GPL-3.0
 */

namespace mustache;

/**
 * This class represents a Mustache delimiter. A delimiter is bounded by a start and a stop tag.
 * 
 * @author Dri <switcher.framework@gmail.com>
 * @license http://www.opensource.org/licenses/gpl-3.0.html GPL-3.0
 * @since 1.0.0
 */
final class Delimiter
{
	/**
	 * An raw version of the current start tag.
	 * @var string
	 */
	public $unquotedStart = '{{';
	
	/**
	 * Indicates whether a normal tag has a higher priority than an escape tag when they're found
	 * at the very same position. For instance, the escape tag <i>{{{</i> overlaps the default
	 * normal tag <i>{{</i>.
	 * @var bool
	 */
	public $precede = false;
	
	/**
	 * The current start tag.
	 * @var string
	 */
	public $start = '\{\{';
	
	/**
	 * The current stop tag.
	 * @var string
	 */
	public $stop = '\}\}';
	
	/**
	 * Defines new tags for the delimiter. The new tags must be different from the escape tags.
	 * 
	 * @param string $start The new start tag
	 * @param string $stop The new stop tag
	 * @throws \InvalidArgumentException If one of the tags is an escape tag
	 */
	public function setTags($start, $stop)
	{
		if ($start == '{{{' || $stop == '}}}')
		{
			throw new \InvalidArgumentException('Normal tags cannot override escape tags');
		}
		
		$this->unquotedStart = $start;
		$this->precede = strlen($start) > 3;
		$this->start = preg_quote($start, '~');
		$this->stop  = preg_quote($stop,  '~');
	}
}

?>